﻿$.ajaxSetup({ cache: false });

 function ShowOrderCount(h, ProdID) {
    document.getElementById("dialog").style.display = "block";
    document.getElementById("dialog").style.top = (h - 1) * 31 + 0 + "px";
    document.getElementById("txtProductID").value = ProdID;
    return false;
}

function Ok() {
    var count = document.getElementById("txtOrderCount").value;
    var productID = document.getElementById("txtProductID").value;
    if (count < 0) {
        alert("订购的货品数量不能小于0！");
        return false;
    }
    var parameter = {};
    parameter['ProductID'] = productID;
    parameter['Count'] = count;
    $.ajax({
        type: "POST",
        //contentType: "application/json",
        url: "../Service/OrderService.aspx",
        data: parameter,
        dataType: 'json',
        beforeSend: function (XMLHttpRequest) {

        },
        success: function (result) {     //回调函数，result，返回值 
            if (result.IsSuccess) {
                alert('已添加到购物车');
                $('#cphMain_chpMain_btnRefersh').click();
            } else {
                alert(result.Result);
            }
        },
        complete: function (XMLHttpRequest, textStatus) {
        },
        error: function () {
            alert('发生错误，请联系管理员.');
        }
    });

}

function Cancel() {
    document.getElementById("dialog").style.display = "none";
    return false;
}

function myKeyDown() {
    k = window.event ? evt.keyCode : evt.which;
    if ((k == 46) || (k == 8) || (k == 189) || (k == 109) || (k == 190) || (k == 110) || (k >= 48 && k <= 57) || (k >= 96 && k <= 105) || (k >= 37 && k <= 40)) {
        document.getElementById("txtMessage").innerHTML = "";
    } else if (k == 13) {
        window.event.keyCode = 9;
    } else {
        document.getElementById("txtMessage").innerHTML = "只能输入数字"; window.event.returnValue = false;
    }
}
function myKeyDown(id) {
    var val = document.getElementById(id).value;
    if (!/^\d{0,4}(\.\d{0,1})?$/.test(val)) {
        document.getElementById(id).value = "";
        document.getElementById("txtMessage").innerHTML = "范围:0-9999.9";
        return false;
    } else {
        document.getElementById("txtMessage").innerHTML = "";
    }
    return true;
}